#!/bin/bash


if [ $# -ne 6 ]
then
    echo "Error: incorrect number of arguments."
    echo "Usage: convert-to-latex.sh compile_latex in_file in_tree_type in_tree_format in_file_format output_dir"
    exit
fi


script_dir=$(dirname $0)
dist=$script_dir/../bin
pkg=edu.washington.ling.syntric.proc
jar_dir=$script_dir/../jars
latex_dir=$script_dir/../latex

compile_latex=$1
in_file=$2
in_tree_type=$3
in_tree_format=$4
in_file_format=$5
output_dir=$6

# Set up output directory
if [ ! -d $output_dir ]; then
	if ! mkdir $output_dir ; then
		echo Error: output_dir=\'$output_dir\' was not valid
		echo Please specify a valid output directory
		exit
	fi
fi

echo %%
echo %% Converting to LaTeX
echo %%
if [ -d $output_dir/latex ]; then
	rm -rf $output_dir/latex
fi
mkdir $output_dir/latex
java -cp $dist:$jar_dir/* $pkg.ConvertFormat $in_file $output_dir/latex/trees.tex --input-tree-type $in_tree_type --input-tree-format $in_tree_format --input-file-format $in_file_format --output-tree-format latex --output-file-format latex

if $compile_latex; then
    $latex_dir/scripts/compile-latex-under-dir.sh $output_dir
fi

